home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / DiceSource / lib / fd / close.c < prev    next >
C/C++ Source or Header  |  1997-09-09  |  924b  |  57 lines

  1.  
  2. /*
  3.  *  CLOSE.C
  4.  *
  5.  *    (c)Copyright 1992-1997 Obvious Implementations Corp.  Redistribution and
  6.  *    use is allowed under the terms of the DICE-LICENSE FILE,
  7.  *    DICE-LICENSE.TXT.
  8.  */
  9.  
  10. #include <clib/dos_protos.h>
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <fcntl.h>
  14. #include <ioctl.h>
  15. #include <errno.h>
  16. #include <lib/misc.h>
  17.  
  18. int __InUnixFork;
  19.  
  20. void
  21. __closeall(void)
  22. {
  23.     short fd;
  24.  
  25.     for (fd = 0; fd < _IoFDLimit; ++fd)
  26.     close(fd);
  27. }
  28.  
  29. int
  30. close(fd)
  31. int fd;
  32. {
  33.     _IOFDS *d;
  34.     int r = -1;
  35.  
  36.     if (d = __getfh(fd)) {
  37.     if (__InUnixFork)
  38.         return(0);
  39.  
  40.     if (d->fd_FileName)
  41.         free(d->fd_FileName);
  42.     if (d->fd_Exec) {                       /*  special */
  43.         r = (*d->fd_Exec)(d->fd_Fh, IOC_CLOSE, NULL, NULL);
  44.     } else {
  45.         r = 0;
  46.         if ((d->fd_Flags & O_NOCLOSE) == 0)
  47.         Close(d->fd_Fh);
  48.     }
  49.     d->fd_Flags = 0;
  50.     d->fd_Exec  = NULL;
  51.     d->fd_Fh    = NULL;
  52.     d->fd_FileName = NULL;
  53.     }
  54.     return(r);
  55. }
  56.  
  57.